<!--
	Carnegie Mellon University
	School of Computer Science
	MSIT eBusiness Technology

	Team 8 - Infinity (2011 Spring)
	infinity-team8@googlegroups.com

	Professor: Jeffrey L. Eppinger
	Program Faculty: Sujata Telang
-->

<jsp:include page="employee-template-top.jsp" />
<jsp:include page="employee-topnav.jsp" />
<%@ page import="databean.FundBean" %>
<%@ page import="model.FundPriceHistoryDAO" %>
<%@ page import="model.GlobalDAO" %>
<%@ page import="databean.FundPriceHistoryBean" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>


<div id="header">
	<h1>Transition Day</h1>
</div>

<jsp:include page="employee-sidebar.jsp" />
<form method="post">
<div id="content">
	<div id="form-wrapper">
		<jsp:include page="employee-error-list.jsp" />
	
			
				<input type="hidden" name="redirect" value="${redirect}"/>
			
			<div class="line-wrap">
				<label>Date  </label>
				<div class="field">
				<%
					GlobalDAO globalDAO = new GlobalDAO();
				
					String currentDate;
					if (globalDAO.lookup("lastTradingDay")==null) {
						currentDate = "";
					} else {
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
						Date d = globalDAO.lookup("lastTradingDay").getDate();
						currentDate = sdf.format(d);
					}
				%>
					
				<input type="text" name="date" value="<%=currentDate%>"/>
				
				</div>
			</div>
			
			<div class="line-wrap">			
				<div class="des"><br/>format: yyyy-mm-dd	</div>
			</div>
			
			
	<div id="blank-box"></div>

	<table id="minimal" summary="transition day">
		<thead>
			<tr>
				<th scope="col">Name</th>
				<th scope="col">Symbol</th>
				<th scope="col">Current Price</th>
				<th scope="col">Closing Price</th>
			</tr>
		</thead>			
			
			<%
				FundPriceHistoryDAO fundPriceHistoryDAO = new FundPriceHistoryDAO();
				
			
				FundBean[] funds = (FundBean[]) request.getAttribute("fundList");
			
				for (FundBean fund : funds) {
			%>
		
		<tbody>
			<tr>
				<td><%=fund.getName()%></td>
				<td><%=fund.getSymbol()%></td>
				<%
					String lastClosingPrice;
					if (globalDAO.lookup("lastTradingDay")==null) {
						lastClosingPrice = "Unavailable";
					} else {
						
						if (fundPriceHistoryDAO.lookup(fund.getFundID(), globalDAO.lookup("lastTradingDay").getDate())==null) {
							lastClosingPrice = "Unavailable";
						} else {
							lastClosingPrice = "$" + fundPriceHistoryDAO.getPriceFormatted(fund.getFundID(), globalDAO.lookup("lastTradingDay").getDate());
						}
						
					}
				%>
				<td><%=lastClosingPrice%></td>
				<td>$<input class="short" type="text" name="price<%=fund.getFundID()%>" value=""/></td>
			</tr>

			<%
				}
			%>
		</tbody>
	</table>
				<div class="button"><input type="submit" name="button" value="Execute!"/></div>
	</div>
	</div>
	</form>
<jsp:include page="footer.jsp" />	
		
